package ee.rsi2m.goproject.util;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;

import ee.rsi2m.goproject.model.GoBoard;
import ee.rsi2m.goproject.model.GoStone;

public class DrawHelper {

	public static int MAGIC_NUMBER;
	public static final int radius = 5;

	public static void drawVerticalGuideLine(Canvas canvas, GoStone stone,
			Paint paint) {
		Paint newpaint = new Paint();
		newpaint.setColor(Color.RED);
		newpaint.setStrokeWidth(5);
		canvas.drawLine(stone.getX(), 0, stone.getX(), 1000, newpaint);
	}

	public static void drawHorizontalGuideLine(Canvas canvas, GoStone stone,
			Paint paint) {
		Paint newpaint = new Paint();
		newpaint.setColor(Color.RED);
		newpaint.setStrokeWidth(5);
		canvas.drawLine(0, stone.getY(), 1000, stone.getY(), newpaint);
	}

	public static void drawEyes(Canvas canvas, GoBoard board, Paint paint) {

		if (board.size == 9) {
			MAGIC_NUMBER = 3;
		} else {
			MAGIC_NUMBER = 4;
		}

		drawFirstLineOfEyes(canvas, board);
		drawSecondLineOfEyes(canvas, board);
		drawThirdLineOfEyes(canvas, board);

	}

	private static void drawThirdLineOfEyes(Canvas canvas, GoBoard board) {
		GoStone stone = board.boardState[MAGIC_NUMBER][(board.size + 1)
				- MAGIC_NUMBER];
		drawSingleEye(canvas, stone.getX(), stone.getY(), radius);

		stone = board.boardState[(board.size + 1) / 2][(board.size + 1)
				- MAGIC_NUMBER];
		drawSingleEye(canvas, stone.getX(), stone.getY(), radius);

		stone = board.boardState[(board.size + 1) - MAGIC_NUMBER][(board.size + 1)
				- MAGIC_NUMBER];
		drawSingleEye(canvas, stone.getX(), stone.getY(), radius);
	}

	private static void drawSecondLineOfEyes(Canvas canvas, GoBoard board) {
		GoStone stone = board.boardState[MAGIC_NUMBER][(board.size + 1) / 2];
		drawSingleEye(canvas, stone.getX(), stone.getY(), radius);

		stone = board.boardState[(board.size + 1) / 2][(board.size + 1) / 2];
		drawSingleEye(canvas, stone.getX(), stone.getY(), radius);

		stone = board.boardState[(board.size + 1) - MAGIC_NUMBER][(board.size + 1) / 2];
		drawSingleEye(canvas, stone.getX(), stone.getY(), radius);
	}

	private static void drawFirstLineOfEyes(Canvas canvas, GoBoard board) {

		GoStone stone = board.boardState[MAGIC_NUMBER][MAGIC_NUMBER];
		drawSingleEye(canvas, stone.getX(), stone.getY(), radius);

		stone = board.boardState[(board.size + 1) / 2][MAGIC_NUMBER];
		drawSingleEye(canvas, stone.getX(), stone.getY(), radius);

		stone = board.boardState[(board.size + 1) - MAGIC_NUMBER][MAGIC_NUMBER];
		drawSingleEye(canvas, stone.getX(), stone.getY(), radius);

	}

	private static void drawSingleEye(Canvas canvas, float x, float y, int radius) {
		canvas.drawCircle(x, y, radius, new Paint());
	}

}
